package frame.options.simulation.results.virtual.summary;

import java.util.List;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import model.components.networks.virtual.VirtualNetwork;

@SuppressWarnings("serial")
public class VirtualNetworksTable extends JTable
{
	private List< List< VirtualNetwork > > virtualNetworksNetworks;
	public List< List< VirtualNetwork > > getVirtualNetworksNetworks(){ return virtualNetworksNetworks; }
	public void setVirtualNetworksNetworks( List< List< VirtualNetwork > > virtualNetworksNetworks ){ this.virtualNetworksNetworks = virtualNetworksNetworks; }

	public VirtualNetworksTable( List< List< VirtualNetwork > > virtualNetworksNetworks )
	{	
		this.setVirtualNetworksNetworks( virtualNetworksNetworks );
		
		this.setModel( this.defaultTableModel() );
		this.setEnabled( false );
	}
	
	private DefaultTableModel defaultTableModel()
	{
		DefaultTableModel defaultTableModel = new DefaultTableModel( new String[]{ "<html><b>Network</b></html>", "<html><b>Cost</b></html>" }, 0 );
		int networksCost = 0;
		
		for( List< VirtualNetwork > virtualNetworkNetworks: this.getVirtualNetworksNetworks() )
		{
			int networkCost = 0;
			
			for( VirtualNetwork virtualNetworkNetwork: virtualNetworkNetworks )
				networkCost += virtualNetworkNetwork.getNetworkCost();
			
			networksCost += networkCost;			
			defaultTableModel.addRow( new Object[]{ "<html><b>" + virtualNetworkNetworks.get( 0 ).getName() + "</b></html>", networkCost } );
		}
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Total</b></html>", "<html><b>" + networksCost + "</b></html>" } );
		
		return defaultTableModel;
	}
	
}
